import axios from "./axios";
const qs = require('qs');
export const getData = () => {
   return axios.request(
      {
         url: '/home/getData',
      }
   )
}

export const getUser = (params) => {
   return axios.request({
      url: "/user/getUser",
      method: 'get',
      params
   })
}

//发送post请求 这里的是登录的用
export const getMenu = (params) => {
   return axios.request({
      url: '/api/login',
      method: 'post',
      data: qs.stringify(params),
      headers: { 'Content-Type': "application/x-www-form-urlencoded" }
   })
}
//发送post请求 这里的是注册的用

export const getNew = (params) => {
   return axios.request({
      url: '/api/reguser',
      method: 'post',
      data: params,
      headers: { 'Content-Type': 'multipart/form-data' }
   })
}
// 发送get请求 这里的是获取用户信息用
export const getUserInfo = (params) => {
   return axios.request({
      url: '/my/userinfo',
      method: 'get',
      headers: {
         'Content-Type': "application/x-www-form-urlencoded",
         'Authorization': params
      }
   })
}

//发起Post请求 这里是修改用户头像用
export const getUserAvatar = (params) => {
   return axios.request({
      url: '/my/update/avatar',
      method: 'post',
      data: qs.stringify(params[0]),
      headers: {
         'Content-Type': "application/x-www-form-urlencoded",
         'Authorization': params[1]
      }
   })
}

export const editUserInfo = (params) => {
   return axios.request({
      url: '/my/userinfo',
      method: 'post',
      data: params[0],
      headers: {
         'Content-Type': "multipart/form-data",
         'Authorization': params[1]
      }
   })
}

export const editUserPassword = (params) => {
   return axios.request({
      url: '/my/updatepwd',
      method: 'post',
      data: qs.stringify(params[0]),
      headers: {
         'Content-Type': "application/x-www-form-urlencoded",
         'Authorization': params[1]
      }
   })
}

export const getCates = (params) => {
   return axios.request({
      url: '/my/article/cates',
      method: 'get',
      headers: {
         'Content-Type': "application/x-www-form-urlencoded",
         'Authorization': params
      }
   })
}

export const deleteCate = (params) => {
   return axios.request({
      url: `/my/article/deletecate/${params[0]}`,
      method: 'delete',
      headers: {
         'Authorization': params[1]
      }
   })
}

export const updatecate = (params) => {
   return axios.request({
      url: '/my/article/updatecate',
      method: 'post',
      data: qs.stringify(params[0]),
      headers: {
         'Content-Type': "application/x-www-form-urlencoded",
         'Authorization': params[1]
      }
   })
}

export const addCate = (params) => {
   return axios.request({
      url: '/my/article/addcates',
      method: 'post',
      data: qs.stringify(params[0]),
      headers: {
         'Content-Type': "application/x-www-form-urlencoded",
         'Authorization': params[1]
      }
   })
}

export const getArticles = (params) => {
   return axios.request({
      url: `/my/article/cates/${params[0]}`,
      method: 'get',
      headers: {
         'Content-Type': "application/x-www-form-urlencoded",
         'Authorization': params[1]
      }
   })
}

export const getallproducts = () => {
   return axios.request({
      url: `http://127.0.0.1:3002/api/shop/allproducts`,
      method: 'get',
      headers: {
         'Content-Type': "application/x-www-form-urlencoded",
      }
   })
}
export const updateproduct = (params) => {
   return axios.request({
      url: `/api/shop/updateproduct/${params[0]}`,
      method: 'post',
      data: params[1],
      headers: {
         'Content-Type': "multipart/form-data",
      }
   })
}

export const deleteproduct = (params) => {
   return axios.request({
      url: `/api/shop/product/${params}`,
      method: 'delete',
      headers: {
         'Content-Type': "application/x-www-form-urlencoded",
      }
   })
}

export const  addproduct= (params) => {
   return axios.request({
      url: `/api/shop/addproduct`,
      method: 'post',
      data: params,
      headers: {
         'Content-Type': "multipart/form-data",
      }
   })
}